**************************************************************************************************
*** This do file creates the replication results for 
*** Free-Riding in Alliances: Testing an Old Theory with a New Method
*** 
*** Thomas Pl�mper (University of Essex)														
*** Eric Neumayer (LSE)					
*** 									
*** Published in: Conflict Management and Peace Science, 2014													
**************************************************************************************************
**************************************************************************************************
/* Note: 
You have to change "local DIR" to the directory you copy the original stata files contained 	*/
/* in the zip file and then run the do file. 													*/
**************************************************************************************************

drop _all
clear matrix
clear mata

capture net install outreg2, from(http://fmwww.bc.edu/RePEc/bocode/o)			/* checks whether outreg2 is installed 		*/

***********************************************************************************
local DIR = "d:\Research\Conflict\Military data\Whitten data\"  /*change relative path to the directory where the files are located */
cd "`DIR'"
***********************************************************************************

use "Article for CMPS (alliances).dta", clear

tsset ccode year

* Table 1*** Add country-specific spatial effects: who are the free-riders?

/* List of country codes:
20	Canada
200	Great Britain
205	Ireland
210	Netherlands
211	Belgium
220	France
230	Spain
235	Portugal
255	Germany
305	Austria
325	Italy
350	Greece
375	Finland
380	Sweden
385	Norway
390	Denmark
640	Turkey
*/

* Summary desciptive stats (table 1)
quietly xi: reg milex_def_growth  l.milex_def_growth ccode#c.us_milex_def_growth ccode#c.soviet_milex_def_growth_if_exc      real_GDP_gr     milconf_sum_intensity_coldwar  milex_gdp_initial3yrs year   SE_var_main_contig_w if ccode>2 & ccode!=395 & ccode!=205 & ccode!=305 & ccode!=375 & ccode!=380  & ccode!=900 & ccode!=920 & ccode!=740 & ccode!=225 & ccode!=230 & year>1955 & year<1989,   robust cluster(country)
su milex_def_growth  us_milex_def_growth soviet_milex_def_growth_if_exc     real_GDP_gr     milconf_sum_intensity_coldwar  milex_gdp_initial3yrs   SE_var_main_contig_w if e(sample)

* Main estimations
xi: reg milex_def_growth  l.milex_def_growth ccode#c.us_milex_def_growth ccode#c.soviet_milex_def_growth_if_exc      real_GDP_gr     milconf_sum_intensity_coldwar  milex_gdp_initial3yrs year   SE_var_main_contig_w if ccode>2 & ccode!=395 & ccode!=205 & ccode!=305 & ccode!=375 & ccode!=380  & ccode!=900 & ccode!=920 & ccode!=740 & ccode!=225 & ccode!=230 & year>1955 & year<1989,   robust cluster(country)
outreg2 using table2, replace excel  

capture drop freeride_degree
gen freeride_degree=.
replace freeride_degree=_b[20b.ccode#c.us_milex_def_growth]+ _b[20b.ccode#c.soviet_milex_def_growth_if_exc] if ccode==20
replace freeride_degree=_b[200.ccode#c.us_milex_def_growth]+ _b[200.ccode#c.soviet_milex_def_growth_if_exc] if ccode==200
replace freeride_degree=_b[210.ccode#c.us_milex_def_growth]+ _b[210.ccode#c.soviet_milex_def_growth_if_exc] if ccode==210
replace freeride_degree=_b[211.ccode#c.us_milex_def_growth]+ _b[211.ccode#c.soviet_milex_def_growth_if_exc] if ccode==211
replace freeride_degree=_b[220.ccode#c.us_milex_def_growth]+ _b[220.ccode#c.soviet_milex_def_growth_if_exc] if ccode==220
replace freeride_degree=_b[235.ccode#c.us_milex_def_growth]+ _b[235.ccode#c.soviet_milex_def_growth_if_exc] if ccode==235
replace freeride_degree=_b[255.ccode#c.us_milex_def_growth]+ _b[255.ccode#c.soviet_milex_def_growth_if_exc] if ccode==255
replace freeride_degree=_b[325.ccode#c.us_milex_def_growth]+ _b[325.ccode#c.soviet_milex_def_growth_if_exc] if ccode==325
replace freeride_degree=_b[350.ccode#c.us_milex_def_growth]+ _b[350.ccode#c.soviet_milex_def_growth_if_exc] if ccode==350
replace freeride_degree=_b[385.ccode#c.us_milex_def_growth]+ _b[385.ccode#c.soviet_milex_def_growth_if_exc] if ccode==385
replace freeride_degree=_b[390.ccode#c.us_milex_def_growth]+ _b[390.ccode#c.soviet_milex_def_growth_if_exc] if ccode==390
replace freeride_degree=_b[640.ccode#c.us_milex_def_growth]+ _b[640.ccode#c.soviet_milex_def_growth_if_exc] if ccode==640

replace freeride_degree=freeride_degree*-1

pwcorr freeride_degree real_GDP_1956_to_1988_av if year==1980, sig
spearman freeride_degree real_GDP_1956_to_1988_av if year==1980, 

pwcorr freeride_degree real_GDP_1956_to_1988_av if year==1980 & ccode!=235, sig
spearman freeride_degree real_GDP_1956_to_1988_av if year==1980 & ccode!=235, 

* Try Palmer (1990, ISQ) groups of smaller and larger non-US allies
capture dropvars palmer_group_*
gen palmer_group_small=0
replace palmer_group_small=1 if country=="Netherlands" | country=="Canada" | country=="Norway" | country=="Denmark" | country=="Belgium" | country=="Greece" | country=="Turkey" | country=="Portugal" 

gen palmer_group_big=0
replace palmer_group_big=1 if country=="United Kingdom" | country=="France" | country=="Germany" | country=="Italy"

pwcorr freeride_degree palmer_group_small if year==1980, sig
spearman freeride_degree palmer_group_small if year==1980, 

pwcorr freeride_degree palmer_group_small if year==1980 & ccode!=235, sig
spearman freeride_degree palmer_group_small if year==1980 & ccode!=235, 


pwcorr freeride_degree  number_borders_with_WP if year==1980 & ccode!=235, sig
spearman freeride_degree  number_borders_with_WP if year==1980 & ccode!=235,

pwcorr freeride_degree   borders_with_WP_dummy if year==1980 & ccode!=235, sig
spearman freeride_degree   borders_with_WP_dummy if year==1980 & ccode!=235, 
 
pwcorr freeride_degree  number_contiguity_with_WP if year==1980 & ccode!=235, sig
spearman freeride_degree  number_contiguity_with_WP if year==1980 & ccode!=235,

pwcorr freeride_degree   contig_with_WP_dummy if year==1980 & ccode!=235, sig
spearman freeride_degree   contig_with_WP_dummy if year==1980 & ccode!=235, 

pwcorr freeride_degree    dist_to_SU if year==1980 & ccode!=235, sig
spearman freeride_degree    dist_to_SU if year==1980 & ccode!=235, 

pwcorr freeride_degree    distcap_to_SU if year==1980 & ccode!=235, sig
spearman freeride_degree    distcap_to_SU if year==1980 & ccode!=235, 

pwcorr freeride_degree    distw_to_SU if year==1980 & ccode!=235, sig
spearman freeride_degree    distw_to_SU if year==1980 & ccode!=235, 

pwcorr freeride_degree    distwces_to_SU if year==1980 & ccode!=235, sig
spearman freeride_degree    distwces_to_SU if year==1980 & ccode!=235, 



* Estimate time-varying response functions (Vietnam war)
capture drop vietnam
gen vietnam=0
replace vietnam=1 if year>=1965 & year<=1973
xi: reg milex_def_growth  l.milex_def_growth vietnam#ccode#c.us_milex_def_growth vietnam#ccode#c.soviet_milex_def_growth_if_exc      real_GDP_gr   milconf_sum_intensity_coldwar  milex_gdp_initial3yrs year   SE_var_main_contig_w if ccode>2 & ccode!=395 & ccode!=205 & ccode!=305 & ccode!=375 & ccode!=380  & ccode!=900 & ccode!=920 & ccode!=740 & ccode!=225 & ccode!=230 & year>1955 & year<1989,   robust cluster(country)
outreg2 using table3, replace excel  

quietly xi: reg milex_def_growth  l.milex_def_growth ccode#c.us_milex_def_growth ccode#c.soviet_milex_def_growth_if_exc      real_GDP_gr     milconf_sum_intensity_coldwar  milex_gdp_initial3yrs year   SE_var_main_contig_w if ccode>2 & ccode!=395 & ccode!=205 & ccode!=305 & ccode!=375 & ccode!=380  & ccode!=900 & ccode!=920 & ccode!=740 & ccode!=225 & ccode!=230 & year>1955 & year<1989,  
est store main
quietly xi: reg milex_def_growth  l.milex_def_growth vietnam#ccode#c.us_milex_def_growth vietnam#ccode#c.soviet_milex_def_growth_if_exc      real_GDP_gr   milconf_sum_intensity_coldwar  milex_gdp_initial3yrs year   SE_var_main_contig_w if ccode>2 & ccode!=395 & ccode!=205 & ccode!=305 & ccode!=375 & ccode!=380  & ccode!=900 & ccode!=920 & ccode!=740 & ccode!=225 & ccode!=230 & year>1955 & year<1989, 
est store robust
suest main robust, cluster(country)
lincom  ( [main_mean]_b[20b.ccode#c.us_milex_def_growth]+[main_mean]_b[20b.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.vietnam#20b.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.vietnam#20b.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[200.ccode#c.us_milex_def_growth]+[main_mean]_b[200.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.vietnam#200.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.vietnam#200.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[210.ccode#c.us_milex_def_growth]+[main_mean]_b[210.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.vietnam#210.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.vietnam#210.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[211.ccode#c.us_milex_def_growth]+[main_mean]_b[211.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.vietnam#211.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.vietnam#211.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[220.ccode#c.us_milex_def_growth]+[main_mean]_b[220.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.vietnam#220.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.vietnam#220.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[235.ccode#c.us_milex_def_growth]+[main_mean]_b[235.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.vietnam#235.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.vietnam#235.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[255.ccode#c.us_milex_def_growth]+[main_mean]_b[255.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.vietnam#255.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.vietnam#255.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[325.ccode#c.us_milex_def_growth]+[main_mean]_b[325.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.vietnam#325.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.vietnam#325.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[350.ccode#c.us_milex_def_growth]+[main_mean]_b[350.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.vietnam#350.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.vietnam#350.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[385.ccode#c.us_milex_def_growth]+[main_mean]_b[385.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.vietnam#385.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.vietnam#385.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[390.ccode#c.us_milex_def_growth]+[main_mean]_b[390.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.vietnam#390.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.vietnam#390.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[640.ccode#c.us_milex_def_growth]+[main_mean]_b[640.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.vietnam#640.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.vietnam#640.ccode#c.soviet_milex_def_growth_if_exc])

* Estimate time-varying response functions (Soviet-Afghan war)
capture drop afghan
gen afghan=0
replace afghan=1 if year>=1980
xi: reg milex_def_growth  l.milex_def_growth afghan#ccode#c.us_milex_def_growth afghan#ccode#c.soviet_milex_def_growth_if_exc     real_GDP_gr   milconf_sum_intensity_coldwar  milex_gdp_initial3yrs year   SE_var_main_contig_w if ccode>2 & ccode!=395 & ccode!=205 & ccode!=305 & ccode!=375 & ccode!=380  & ccode!=900 & ccode!=920 & ccode!=740 & ccode!=225 & ccode!=230 & year>1955 & year<1989,   robust cluster(country)
outreg2 using table3, append excel  

quietly xi: reg milex_def_growth  l.milex_def_growth ccode#c.us_milex_def_growth ccode#c.soviet_milex_def_growth_if_exc      real_GDP_gr     milconf_sum_intensity_coldwar  milex_gdp_initial3yrs year   SE_var_main_contig_w if ccode>2 & ccode!=395 & ccode!=205 & ccode!=305 & ccode!=375 & ccode!=380  & ccode!=900 & ccode!=920 & ccode!=740 & ccode!=225 & ccode!=230 & year>1955 & year<1989,  
est store main
quietly xi: reg milex_def_growth  l.milex_def_growth afghan#ccode#c.us_milex_def_growth afghan#ccode#c.soviet_milex_def_growth_if_exc      real_GDP_gr   milconf_sum_intensity_coldwar  milex_gdp_initial3yrs year   SE_var_main_contig_w if ccode>2 & ccode!=395 & ccode!=205 & ccode!=305 & ccode!=375 & ccode!=380  & ccode!=900 & ccode!=920 & ccode!=740 & ccode!=225 & ccode!=230 & year>1955 & year<1989, 
est store robust
suest main robust, cluster(country)
lincom  ( [main_mean]_b[20b.ccode#c.us_milex_def_growth]+[main_mean]_b[20b.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.afghan#20b.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.afghan#20b.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[200.ccode#c.us_milex_def_growth]+[main_mean]_b[200.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.afghan#200.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.afghan#200.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[210.ccode#c.us_milex_def_growth]+[main_mean]_b[210.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.afghan#210.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.afghan#210.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[211.ccode#c.us_milex_def_growth]+[main_mean]_b[211.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.afghan#211.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.afghan#211.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[220.ccode#c.us_milex_def_growth]+[main_mean]_b[220.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.afghan#220.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.afghan#220.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[235.ccode#c.us_milex_def_growth]+[main_mean]_b[235.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.afghan#235.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.afghan#235.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[255.ccode#c.us_milex_def_growth]+[main_mean]_b[255.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.afghan#255.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.afghan#255.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[325.ccode#c.us_milex_def_growth]+[main_mean]_b[325.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.afghan#325.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.afghan#325.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[350.ccode#c.us_milex_def_growth]+[main_mean]_b[350.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.afghan#350.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.afghan#350.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[385.ccode#c.us_milex_def_growth]+[main_mean]_b[385.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.afghan#385.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.afghan#385.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[390.ccode#c.us_milex_def_growth]+[main_mean]_b[390.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.afghan#390.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.afghan#390.ccode#c.soviet_milex_def_growth_if_exc])
lincom  ( [main_mean]_b[640.ccode#c.us_milex_def_growth]+[main_mean]_b[640.ccode#c.soviet_milex_def_growth_if_exc])- ( [robust_mean]_b[0.afghan#640.ccode#c.us_milex_def_growth]+[robust_mean]_b[0.afghan#640.ccode#c.soviet_milex_def_growth_if_exc])

* Include unit fixed effects and country-specific linear year trends estimations
xi: xtreg milex_def_growth  l.milex_def_growth ccode#c.us_milex_def_growth ccode#c.soviet_milex_def_growth_if_exc      real_GDP_gr     milconf_sum_intensity_coldwar  milex_gdp_initial3yrs ccode#c.year   SE_var_main_contig_w if ccode>2 & ccode!=395 & ccode!=205 & ccode!=305 & ccode!=375 & ccode!=380  & ccode!=900 & ccode!=920 & ccode!=740 & ccode!=225 & ccode!=230 & year>1955 & year<1989,   robust cluster(country) fe
outreg2 using table3, append excel  


* Replace Soviet with Warsaw Pact military spending
xi: reg milex_def_growth  l.milex_def_growth ccode#c.us_milex_def_growth ccode#c.warsaw_milex_def_growth_if_exc     real_GDP_gr     milconf_sum_intensity_coldwar  milex_gdp_initial3yrs year   SE_var_main_contig_w if ccode>2 & ccode!=395 & ccode!=205 & ccode!=305 & ccode!=375 & ccode!=380  & ccode!=900 & ccode!=920 & ccode!=740 & ccode!=225 & ccode!=230 & year>1955 & year<1989,   robust cluster(country)
outreg2 using table3, append excel  

* Include further control variables
xi: reg milex_def_growth  l.milex_def_growth ccode#c.us_milex_def_growth ccode#c.soviet_milex_def_growth_if_exc      real_GDP_gr     milconf_sum_intensity_coldwar GOV_min GOV_npty election_yr  GOV_welfare  GOV_hawk1   year if ccode>2 & ccode!=395 & ccode!=205 & ccode!=305 & ccode!=375 & ccode!=380  & ccode!=900 & ccode!=920 & ccode!=740 & ccode!=225 & ccode!=230 & ccode!=235 & ccode!=350 & year>1955 & year<1989,   robust cluster(country)
outreg2 using table3, append excel  


